import { ajax } from '@/utils'

const baseUrl = '/system/dict'

export default {
  getDictTypePage(...args: IGetDictTypePageReq): Promise<IGetDictTypePageRes> {
    return ajax.post(`${baseUrl}/type/page`, args[0])
  },
  createDictType(...args: ICreateDictTypeReq): IVoidRes {
    return ajax.post(`${baseUrl}/type/create`, args[0])
  },
  updateDictType(...args: IUpdateDictTypeReq): IVoidRes {
    return ajax.put(`${baseUrl}/type/update/${args[0]}`, args[1])
  },
  deleteDictType(...args: IDeleteReq): IVoidRes {
    return ajax.delete(`${baseUrl}/type/delete`, { data: args[0] })
  },
  exportDictTypePage(...args: IGetDictTypePageReq): IExportRes {
    return ajax.post(`${baseUrl}/type/export`, args[0], {
      responseType: 'blob'
    })
  },
  getDictType(...args: IGetDictTypeReq): Promise<IGetDictTypeRes> {
    return ajax.get(`${baseUrl}/type`, { params: { id: args[0] } })
  },
  getDictDataPage(...args: IGetDictDataPageReq): Promise<IGetDictDataPageRes> {
    return ajax.post(`${baseUrl}/data/page`, args[0])
  },
  getDictDataList(...args: IGetDictDataListReq): Promise<IGetDictDataListRes> {
    return ajax.get(`${baseUrl}/data/list/${args[0]}`)
  },
  createDictData(...args: ICreateDictDataReq): IVoidRes {
    return ajax.post(`${baseUrl}/data/create`, args[0])
  },
  updateDictData(...args: IUpdateDictDataReq): IVoidRes {
    return ajax.put(`${baseUrl}/data/update/${args[0]}`, args[1])
  },
  deleteDictData(...args: IDeleteReq): IVoidRes {
    return ajax.delete(`${baseUrl}/data/delete`, { data: args[0] })
  },
  exportDictDataPage(...args: IGetDictDataPageReq): IExportRes {
    return ajax.post(`${baseUrl}/data/export`, args[0], {
      responseType: 'blob'
    })
  }
}
